﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GWB.Application;
using GWB.Application.OnLineShare;
using GWB.Application.OnLineShare.Dtos;
using GWB.Utils.Controllers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace Utils.Controllers
{
    public class ToolController : BaseController
    {

        private readonly ILogService _logger;
        private readonly IOnLineShareService _onLineShareService;
        private readonly IHttpContextAccessor context;

        public ToolController(ILogService logger, IOnLineShareService onLineShareService, IHttpContextAccessor accessor)
        {
            _logger = logger;
            context = accessor;
            _onLineShareService = onLineShareService;
        }

        public IActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// JSON格式化
        /// </summary>
        /// <returns></returns>
        public IActionResult JSONFormat()
        {

            return View();
        }

        /// <summary>
        /// 字符串操作
        /// </summary>
        /// <returns></returns>
        public IActionResult StringOperate()
        {

            return View();
        }


        public IActionResult EntityGenerator()
        {
            return View();
        }

        public IActionResult FileManage()
        {
            return View();
        }

        public IActionResult OnLineShare()
        {
            return View();
        }

        public IActionResult ChatGPTIM()
        {
            return View();
        }

        [HttpPost]
        public GWB.Utils.Models.JsonResult GetVisitorLogInfo()
        {
            return new GWB.Utils.Models.JsonResult()
            {

                Data = _logger.GetVisitorLogInfo(),
                Msg = "这是一个警告消息",
                Success = true
            };
        }

        [HttpPost]
        public  GWB.Utils.Models.JsonResult GetSend(string msg)
        {
            return new GWB.Utils.Models.JsonResult()
            {

                Data = _logger.Send(msg),
                Msg = "",
                Success = true
            };
        }

        /// <summary>
        /// 添加分享内容
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        [HttpPost]
        public GWB.Utils.Models.JsonResult AddShareContent([FromBody] ShareContentInputDto inputDto)
        {
            try
            {
                var result = _onLineShareService.AddShareContent(inputDto);

                return new GWB.Utils.Models.JsonResult()
                {
                    Data = result,
                    Success = result

                };
            }
            catch (Exception e)
            {
                Console.WriteLine("错误日志",JsonConvert.SerializeObject(e));
            }

            return null;
        }

        public GWB.Utils.Models.JsonResult AddFile(IFormFile file)
        {
            var result = new GWB.Utils.Models.JsonResult() { Success = true };
            if (file == null)
            {
                result.Success = false;
                result.Msg = "文件不能为空或大小超过限制(1G)";
            }
            _onLineShareService.AddFile(file);
            return result;
        }

        /// <summary>
        /// 获取分享内容
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        [HttpGet]
        public GWB.Utils.Models.JsonResult GetShareContent([FromBody] ShareContentPageInputDto inputDto)
        {

            var vv = HttpContext.Connection;

            var v1 = context.HttpContext.Request.Headers["SERVER_NAME"];       // '获取服务器IP
            var v2 = context.HttpContext.Request.Headers["HTTP_REFERER"];       //       '获取访问来源页面
            var v3 = context.HttpContext.Request.Headers["OS"];       //                              '获取操作系统
            var v4 = context.HttpContext.Request.Headers["APPL_PHYSICAL_PATH"];       //     '获取IIS物理路径
            var v5 = context.HttpContext.Request.Headers["SCRIPT_NAME"];       //                  '获取虚拟路径
            var v6 = context.HttpContext.Request.Headers["NUMBER_OF_PROCESSORS"];       //    '获取服务器CPU个数
            var v7 = context.HttpContext.Request.Headers["SERVER_PORT"];       //                '服务器处理请求的端口
            var v8 = context.HttpContext.Request.Headers["Url"];       //                           返回服务器地址
            var v9 = context.HttpContext.Request.Headers["Path_Info"];       //                 客户端提供的路径信息
            var v10 = context.HttpContext.Request.Headers["Appl_Physical_Path"];       // 与应用程序元数据库路径相应的物理路径
            var v11 = context.HttpContext.Request.Headers["Path_Translated"];       //      通过由虚拟至物理的映射后得到的路径
            var v12 = context.HttpContext.Request.Headers["Script_Name"];       //           执行脚本的名称
            var v13 = context.HttpContext.Request.Headers["Query_String"];       //          查询字符串内容
            var v14 = context.HttpContext.Request.Headers["Http_Referer"];       //          请求的字符串内容
            var v15 = context.HttpContext.Request.Headers["Server_Port"];       //             接受请求的服务器端口号
            var v16 = context.HttpContext.Request.Headers["Remote_Addr"];       //        发出请求的远程主机的IP地址
            var v17 = context.HttpContext.Request.Headers["Remote_Host"];       //        发出请求的远程主机名称
            var v18 = context.HttpContext.Request.Headers["Local_Addr"];       //            返回接受请求的服务器地址
            var v19 = context.HttpContext.Request.Headers["Http_Host"];       //             返回服务器地址
            var v20 = context.HttpContext.Request.Headers["Server_Name"];       //        服务器的主机名、DNS地址或IP地址
            var v21 = context.HttpContext.Request.Headers["Request_Method"];       // 提出请求的方法比如GET、HEAD、POST等等
            var v22 = context.HttpContext.Request.Headers["Server_Port_Secure"];       //    如果接受请求的服务器端口为安全端口时，则为1，否则为0
            var v23 = context.HttpContext.Request.Headers["Server_Protocol"];       //       服务器使用的协议的名称和版本
            var v24 = context.HttpContext.Request.Headers["Server_Software"];       //    应答请求并运行网关的服务器软件的名称和版本
            var v25 = context.HttpContext.Request.Headers["All_Http"];       //    客户端发送的所有HTTP标头，前缀HTTP_
            var v26 = context.HttpContext.Request.Headers["All_Raw"];       //    客户端发送的所有HTTP标头,其结果和客户端发送时一样，没有前缀HTTP_
            var v27 = context.HttpContext.Request.Headers["Appl_MD_Path"];       //    应用程序的元数据库路径
            var v28 = context.HttpContext.Request.Headers["Content_Length"];       //     客户端发出内容的长度
            var v29 = context.HttpContext.Request.Headers["Https"];       //   如果请求穿过安全通道（SSL），则返回ON如果请求来自非安全通道，则返回OFF
            var v30 = context.HttpContext.Request.Headers["Instance_ID"];       //      IIS实例的ID号
            var v31 = context.HttpContext.Request.Headers["Instance_Meta_Path"];       //      响应请求的IIS实例的元数据库路径
            var v32 = context.HttpContext.Request.Headers["Http_Accept_Encoding"];       //   返回内容如：gzip,deflate
            var v33 = context.HttpContext.Request.Headers["Http_Accept_Language"];       //  返回内容如：en - us
            var v34 = context.HttpContext.Request.Headers["Http_Connection"];       //   返回内容：Keep - Alive
            var v35 = context.HttpContext.Request.Headers["Http_Cookie"];       //     返回内容：Cookie的值
            var v36 = context.HttpContext.Request.Headers["Http_User_Agent"];       //     返回内容：Mozilla / 4.0[compatible; MSIE6.0; WindowsNT5.1; SV1]
            var v37 = context.HttpContext.Request.Headers["Https_Keysize"];       //               安全套接字层连接关键字的位数，如128
            var v38 = context.HttpContext.Request.Headers["Https_Secretkeysize"];       //      服务器验证私人关键字的位数如1024
            var v39 = context.HttpContext.Request.Headers["Https_Server_Issuer"];       //      服务器证书的发行者字段
            var v40 = context.HttpContext.Request.Headers["Https_Server_Subject"];       //    服务器证书的主题字段
            var v41 = context.HttpContext.Request.Headers["Auth_Password"];       //              当使用基本验证模式时，客户在密码对话框中输入的密码
            var v42 = context.HttpContext.Request.Headers["Auth_Type"];       //                     是用户访问受保护的脚本时，服务器用於检验用户的验证方法
            var v43 = context.HttpContext.Request.Headers["Auth_User"];       //                代证的用户名
            var v44 = context.HttpContext.Request.Headers["Cert_Cookie"];       //              唯一的客户证书ID号
            var v45 = context.HttpContext.Request.Headers["Cert_Flag"];       //         客户证书标志，如有客户端证书，则bit0为0如果客户端证书验证无效，bit1被设置为1
            var v46 = context.HttpContext.Request.Headers["Cert_Issuer"];       //                 用户证书中的发行者字段
            var v47 = context.HttpContext.Request.Headers["Cert_Keysize"];       //                安全套接字层连接关键字的位数，如128
            var v48 = context.HttpContext.Request.Headers["Cert_Secretkeysize"];       //      服务器验证私人关键字的位数如1024
            var v49 = context.HttpContext.Request.Headers["Cert_Serialnumber"];       //     客户证书的序列号字段
            var v50 = context.HttpContext.Request.Headers["Cert_Server_Issuer"];       //      服务器证书的发行者字段
            var v51 = context.HttpContext.Request.Headers["Cert_Server_Subject"];       //    服务器证书的主题字段
            var v52 = context.HttpContext.Request.Headers["Cert_Subject"];       //                客户端证书的主题字段
            var v53 = context.HttpContext.Request.Headers["Content_Type"];       //              客户发送的form内容或HTTPPUT的数据类型






           

            return new GWB.Utils.Models.JsonResult()
            {
                Data = new
                {
                    v1 = @"v1:" + v1 + "____" +
                       "v2:" + v2 + "____" +
                       "v3:" + v3 + "____" +
                       "v4:" + v4 + "____" +
                       "v5:" + v6 + "____" +
                       "v6:" + v6 + "____" +
                       "v7:" + v7 + "____" +
                       "v8:" + v8 + "____" +
                       "v9:" + v9 + "____" +
                       "v10:" + v10 + "____" +
                       "v11:" + v11 + "____" +
                       "v12:" + v12 + "____" +
                       "v13:" + v13 + "____" +
                       "v14:" + v14 + "____" +
                       "v15:" + v15 + "____" +
                       "v16:" + v16 + "____" +
                       "v17:" + v17 + "____" +
                       "v18:" + v18 + "____" +
                       "v19:" + v19 + "____" +
                       "v20:" + v20 + "____" +
                       "v21:" + v21 + "____" +
                       "v22:" + v22 + "____" +
                       "v23:" + v23 + "____" +
                       "v24:" + v24 + "____" +
                       "v25:" + v25 + "____" +
                       "v26:" + v26 + "____" +
                       "v27:" + v27 + "____" +
                       "v28:" + v28 + "____" +
                       "v29:" + v29 + "____" +
                       "v30:" + v30 + "____" +
                       "v31:" + v31 + "____" +
                       "v32:" + v32 + "____" +
                       "v33:" + v33 + "____" +
                       "v34:" + v34 + "____" +
                       "v35:" + v35 + "____" +
                       "v36:" + v36 + "____" +
                       "v37:" + v37 + "____" +
                       "v38:" + v38 + "____" +
                       "v39:" + v39 + "____" +
                       "v40:" + v40 + "____" +
                       "v41:" + v41 + "____" +
                       "v42:" + v42 + "____" +
                       "v43:" + v43 + "____" +
                       "v44:" + v44 + "____" +
                       "v45:" + v45 + "____" +
                       "v46:" + v46 + "____" +
                       "v47:" + v47 + "____" +
                       "v48:" + v48 + "____" +
                       "v49:" + v49 + "____" +
                       "v50:" + v50 + "____" +
                       "v51:" + v51 + "____" +
                       "v52:" + v52 + "____" +
                       "v53:" + v53 + "____",
                    v5 = JsonConvert.SerializeObject(HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString()),
                   //  v2 = JsonConvert.SerializeObject(HttpContext.Connection.RemoteIpAddress),
                   
                    //v6 = JsonConvert.SerializeObject(HttpContext.Connection.RemoteIpAddress.MapToIPv4()),
                    //v7= JsonConvert.SerializeObject(HttpContext.Connection.RemoteIpAddress),


                },
                Success = true

            };
        }
    }
}